<include file="public@header"/>

<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li><a href="{:url('StudentScore/index')}">学生成绩列表</a></li>
        <li class="active"><a href="{:url('StudentScore/add',['is_teacher'=>$is_teacher])}">添加</a></li>
    </ul>
    <div class="row margin-top-20">
        <div class="col-md-10 col-md-offset-2">
            <form action="{:url('StudentScore/addPost')}" method="post" class="form-horizontal js-ajax-form margin-top-20">
                <input type="hidden" name="is_teacher" id="is_teacher" value="{$is_teacher}">
                <div class="row">
                    <div class="col-md-9">
                        <table class="table table-bordered chase_classroom_table">
                            <tr>
                                <th>学校<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="school_id" id="school_id" style="width:240px;">
                                        <option value='0'>--- 请选择 ---</option>
                                        <notempty name="schools">
                                            <volist name="schools" id="vo">
                                                <if condition="isset($param.school_id) && $param.school_id == $vo.id">
                                                    <option value="{$vo.id}" selected>{$vo.name}</option>
                                                    <else/>
                                                    <option value="{$vo.id}">{$vo.name}</option>
                                                </if>
                                            </volist>
                                        </notempty>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>班级<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="class_id" id="class_id" style="width:240px;">
                                        <option value='0'>--- 请选择 ---</option>
                                    </select>
                                </td>
                            </tr>

                            <tr>
                                <th>课程<span class="form-required">*</span></th>
                                <td>
                                    <input type="text" class="form-control col-md-4" name="course" id="course" value="" readonly>
                                </td>
                            </tr>
                            <tr>
                                <th>学生<span class="form-required">*</span></th>
                                <td>
                                    <select class="form-control" name="student_id" id="student_id" style="width:240px;">
                                        <option value='0'>--- 请选择 ---</option>
                                    </select>
                                </td>
                            </tr>
                            <tr>
                                <th>第一题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question1" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>第二题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question2" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>第三题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question3" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>第四题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question4" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>第五题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question5" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>第六题<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="question6" min="0" max="100" placeholder="请输入分数" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>附加分<span class="form-required">*</span></th>
                                <td>
                                    <input type="number" class="form-control" name="extra_score" min="0" max="100" placeholder="请输入附加分" value="">
                                </td>
                            </tr>
                            <tr>
                                <th>总分<span class="form-required">*</span></th>
                                <td>
                                    <input type="text" class="form-control" name="total_score" id="total_score" min="0" readonly placeholder="请输入总分" value="">
                                </td>
                            </tr>
                        </table>

                        <div class="form-group">
                            <div class="col-sm-offset-2 col-sm-10">
                                <button type="submit" class="btn btn-primary js-ajax-submit">{:lang('ADD')}</button>
                                <a class="btn btn-default" href="{:url('StudentScore/index')}">{:lang('BACK')}</a>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>
<!--ajax layer 弹窗-->
<script type="text/javascript" src="__STATIC__/js/admin.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        //筛选学校
        $('#school_id').on('change',function () {
            var is_teacher = $('#is_teacher').val();
            var sid = $(this).val();
            if(sid == 0){
                $('#class_id').empty();
                var html = '<option value=\"0\">--- 请选择 ---</option>';
                $('#class_id').html(html);
                return false;
            }

            //清空课程和学生
            $('#course').val('');
            $('#student_id').empty();
            var html1 = '<option value=\"0\">--- 请选择 ---</option>';
            $('#student_id').html(html1);

            $.ajax({
                url:"{:url('StudentScore/ajaxClass')}",
                type:'post',
                dataType:'json',
                data:{"school_id":sid, "is_teacher":is_teacher},
                success:function(jsonData){
                    $('#class_id').empty();
                    var html = '<option value=\"0\">--- 请选择 ---</option>';

                    if(jsonData.code == 1){
                        for(var i in jsonData.data){
                            html += '<option value=\"'+jsonData.data[i].id+'\">'+jsonData.data[i].name+'</option>';
                        }
                    }
                    $('#class_id').html(html);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

        //筛选班级
        $('#class_id').on('change',function () {
            var cid = $(this).val();
            if(cid == 0){
                $('#course').val('');
                $('#student_id').empty();
                var html = '<option value=\"0\">--- 请选择 ---</option>';
                $('#student_id').html(html);
                return false;
            }
            $.ajax({
                url:"{:url('StudentScore/ajax_add_class')}",
                type:'post',
                dataType:'json',
                data:{"class_id":cid},
                success:function(jsonData){
                    $('#student_id').empty();
                    $('#course').val('');
                    var html = '<option value=\"0\">--- 请选择 ---</option>';

                    if(jsonData.code == 1){
                        for(var i in jsonData.data){
                            html += '<option value=\"'+jsonData.data[i].student_id+'\">'+jsonData.data[i].student_name+'</option>';
                        }
                        $('#course').val(jsonData.data[0].course_name);
                    }
                    $('#student_id').html(html);
                },
                error:function(XMLHttpRequest, textStatus, errorThrown){
                    console.log('xhr='+XMLHttpRequest.readyState+' status='+textStatus+' error='+errorThrown);
                }
            });
        });

        //计算总分
        $('body').on('change','input[type=number]',function ()
        {
            var ques1 = $('input[name=question1]').val();
            var ques2 = $('input[name=question2]').val();
            var ques3 = $('input[name=question3]').val();
            var ques4 = $('input[name=question4]').val();
            var ques5 = $('input[name=question5]').val();
            var ques6 = $('input[name=question6]').val();
            var extra_score = $('input[name=extra_score]').val();

            if(typeof(ques1) == "undefined" || ques1 == ''){
                ques1 = 0.00;
            }
            if(typeof(ques2) == "undefined" || ques2 == ''){
                ques2 = 0.00;
            }
            if(typeof(ques3) == "undefined" || ques3 == ''){
                ques3 = 0.00;
            }
            if(typeof(ques4) == "undefined" || ques4 == ''){
                ques4 = 0.00;
            }
            if(typeof(ques5) == "undefined" || ques5 == ''){
                ques5 = 0.00;
            }
            if(typeof(ques6) == "undefined" || ques6 == ''){
                ques6 = 0.00;
            }
            if(typeof(extra_score) == "undefined" || extra_score == ''){
                extra_score = 0.00;
            }

            var total = Math.abs(ques1) + Math.abs(ques2) + Math.abs(ques3)+ Math.abs(ques4) +
                Math.abs(ques5) + Math.abs(ques6) + Math.abs(extra_score);
            $('#total_score').val(total.toFixed(2));
        });


    });

</script>

</body>
